<?php
class wms_finder_extend_filter_delivery{

    
    function get_extend_colums()
    {
        $orderTypeObj = app::get('omeauto')->model('order_type');
        $types = $orderTypeObj->getList('tid,name',array('disabled'=>'false','delivery_group'=>'true'));
        $delivery_group = array();
        foreach($types as $type){
            $delivery_group[$type['tid']] = $type['name'];
        }

        $branchObj = app::get('ome')->model('branch');
        if( $_GET['ctl']=='admin_orderform')
        {
            $branch_rows = $branchObj->getList('branch_id,name',array('b_type'=>1),0,-1);
            
        }elseif ($_GET['ctl'] == 'admin_receipts_outer' || $_GET['ctl'] == 'admin_receipts_outerori' || ($_GET['ctl'] == 'admin_receipts_print' && $_GET['act'] == 'outerorilistindex') ){
            $branch_rows = $branchObj->getList('branch_id,name',array('owner'=>'2', 'b_type'=>1),0,-1);
        }else{
            $branch_rows = $branchObj->getList('branch_id,name',array('owner'=>'1', 'b_type'=>1),0,-1);
        }
        $branch_list = array();
        $area_branch = array();
        foreach($branch_rows as $branch){
            $branch_list [$branch['branch_id']] = $branch['name'];
            $area_branch[]=$branch['branch_id'];
        }
        $branchPanel = ($branch_list>1) ? 'delivery_finder_top' : '';

        //add by 判断当前登录用是否是超级管理员，以及拥有的门店
        $area_shopIds=array();
        $is_super = kernel::single('desktop_user')->is_super();
        if (!$is_super) {
            $info = app::get('desktop')->model('users')->dump(kernel::single('desktop_user')->get_id(), 'shopIds');
            if (empty($info['shopIds'])) {
                header('Content-Type:text/html; charset=utf-8');
                echo app::get('desktop')->_("您没有对应店铺权限");exit;
            }
            $shopIds = explode(",", $info['shopIds']);
            $shop = app::get('ome')->model('shop')->getList('shop_id, name', array('shop_id'=>$shopIds));
            unset($shopIds);
            foreach ($shop as $key => $value) {
                $shopIds[$value['shop_id']]=$value['name'];
                $area_shopIds[]=$value['shop_id'];
            }
        } else {
            $shop = app::get('ome')->model('shop')->getList('shop_id, name');
            foreach ($shop as $key => $value) {
                $shopIds[$value['shop_id']]=$value['name'];
                $area_shopIds[]=$value['shop_id'];
            }
        }
        if($_GET['app']=='wms' && $_GET['ctl']=='admin_receipts_print' && $_GET['act']=='index' && $_GET['status']==0)
        {
            //add by ldward 20180522 根据区域判断选择
            $sql='SELECT * from (SELECT ship_province,count(ship_province) qty FROM sdb_wms_delivery 
                WHERE type="normal"  AND (print_status & 4) !=4 and status=0 and process_status in(0,1) and disabled="false" '                ;
            if($_GET['logi_id'])
            {
                $sql.=' and logi_id='.$_GET['logi_id'];   
            }
            if(!empty($_POST['shop_id']))
            {
                $sql.=' and shop_id="'.+$_POST['shop_id'].'"';
            }else{
                $sql.=' and shop_id IN (\''.implode('\',\'', $area_shopIds).'\')';
            }
            if(!empty($_POST['branch_id']))
            {
                $sql.=' and branch_id='.+$_POST['branch_id'];
            }else{
                $sql.=' and branch_id in (\''.implode('\',\'', $area_branch).'\') ';
            }
            $sql.='  and is_ship="true" and is_form="true" and deliverytype!="pickup"
                GROUP BY ship_province)tab where tab.qty>0 order by tab.qty DESC';
            
            $area_datas = kernel::database()->select($sql);
            foreach ($area_datas as $key => $value) 
            {
                $tempcolumn['area['.$value['ship_province'].']'] =  array (
                    'type' => 'checkbox',
                    'label' => $value['ship_province'].'(<font color="red">'.$value['qty'].'</font>)',
                    'width' => 75,
                    'editable' => false,
                    'in_list' => true,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    'panel_id' => 'delivery_finder_top',
                );
            }
        }
        $db['delivery']=array (
            'columns' => array (
                'delivery_time' => array (
                    'type' => 'time',
                    'label' => '发货时间',
                    'comment' => '发货时间',
                    'editable' => false,
                    'filtertype' => 'time',
                    'filterdefault' => true,
                    'in_list' => true,
                ),
                'ship_tel_mobile' => array (
                    'type' => 'varchar(30)',
                    'label' => '收货人联系电话',
                    'comment' => '收货人联系电话',
                    'editable' => false,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    'in_list' => true,
                ),
                'delivery_ident' => array (
                    'type' => 'varchar(30)',
                    'label' => '打印批次号',
                    'width' => 130,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    'editable' => false,
                    'in_list' => true,
                    'default_in_list' => true,
                ),
                'order_bn' => array (
                    'type' => 'varchar(30)',
                    'label' => '订单号',
                    'width' => 130,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    'editable' => false,
                    'in_list' => true,
                    'default_in_list' => true,
                ),
                'logi_no_ext' => array (
                    'type' => 'varchar(50)',
                    'label' => '物流单号',
                    'comment' => '物流单号',
                    'editable' => false,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    'width' =>110,
                ),
		        'logi_no' => array (
                    'type' => 'varchar(50)',
                    'label' => '物流单号',
                    'comment' => '物流单号',
                    'editable' => false,
                    'width' =>110,
                    'in_list' => true,
                    'default_in_list' => true,
                ),
                'member_uname' => array (
                  'type' => 'varchar(50)',
                  'label' => '会员用户名',
                  'width' => 75,
                  'editable' => false,
                  'filtertype' => 'normal',
                  'filterdefault' => 'true',
                  'in_list' => true,
                  'default_in_list' => true,
                ),
                'product_bn' => array (
                    'type' => 'varchar(30)',
                    'label' => '货号',
                    'width' => 85,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    'editable' => false,
                    'in_list' => true,
                    'default_in_list' => true,
                    'panel_id' => 'delivery_finder_top',
                ),
                'product_barcode' => array (
                    'type' => 'varchar(32)',
                    'label' => '条形码',
                    'width' => 110,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    'editable' => false,
                    'in_list' => true,
                    'default_in_list' => true,
                ),
                'skuNum' =>array(
                    'type' => 'skunum',
                    'filtertype' => 'normal',
                    'required' => true,
                    'label' => '商品种类',
                    'comment' => '商品种类数',
                    'editable' => false,
                    'in_list' => true,
                    'default_in_list' => true,
                    'default' => 0,
                    'filterdefault' => true,
                    'panel_id' => 'delivery_finder_top',
                ),
                'itemNum' =>array(
                    'type' => 'skunum',
                    'filtertype' => 'normal',
                    'required' => true,
                    'label' => '商品总数量',
                    'comment' => '商品种类数',
                    'editable' => false,
                    'in_list' => true,
                    'default_in_list' => true,
                    'default' => 0,
                    'filterdefault' => true,
                    'panel_id' => 'delivery_finder_top',
                ),
                'delivery_group' =>array (
                    'type' => $delivery_group,
                    'label' => '发货单分组',
                    'comment' => '发货单分组',
                    'editable' => false,
                    'width' =>75,
                    'filtertype' => 'yes',
                    'filterdefault' => false,
                    'in_list' => false,
                    'panel_id' => 'delivery_finder_top',
                ),
                'branch_id' =>
                    array (
                    'type' => $branch_list,
                    'editable' => false,
                    'label' => '仓库',
                    'width' => 110,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    'in_list' => true,
                    'panel_id' => $branchPanel,
                ),
                'shop_id' =>array (
                  'type' => $shopIds,
                  'label' => '来源店铺',
                  'width' => 75,
                  'editable' => false,
                  'in_list' => true,
                  'filtertype' => 'normal',
                  'filterdefault' => true,
                  'panel_id' => 'delivery_finder_top',
                ),
                'custom_mark' =>array (
                    'type' => 'custom_mark',
                    'label' => '买家留言',
                    'width' => 500,
                    'editable' => false,
                    //'in_list' => true,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    //'default_in_list'=>true
                ),  
                'mark_text' =>array (
                    'type' => 'mark_text',
                    'label' => '客服备注',
                    'width' => 500,
                    'editable' => false,
                    //'in_list' => true,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    //'default_in_list'=>true
                ),
                'net_weight' =>array(
                    'type' => 'money',
                    'label' => '商品净重',
                    'comment' => '商品净重',
                    'width' => 50,
                    'editable' => false,
                    'in_list' => true,
                    'filtertype' => 'normal',
                    'filterdefault' => true,
                    'default_in_list' => true
                )
            )
        );

        foreach ($tempcolumn as $key => $value) {
            
            $db['delivery']['columns'][$key]=$value;
        }

        //第三方发货页面 头部菜单和高级筛选添加单据状态选项
        if($_GET['ctl'] == 'admin_receipts_outer'){
            $db['delivery']['columns']['status'] = array(
                'type' =>array(
                    '0' => '处理中',
                    '1' => '取消',
                    '2' => '暂停',
                    '3' => '已完成',
                ),
                'editable' => false,
                'label' => '单据状态',
                'width' => 110,
                'filtertype' => 'normal',
                'filterdefault' => true,
                'in_list' => true,
                'panel_id' => 'delivery_finder_top',
            );
        }

        if(($_GET['ctl'] == 'admin_receipts_print' && $_GET['status'] == '') || ($_GET['ctl'] == 'admin_delivery' && $_GET['act'] == 'index')){
            $db['delivery']['columns']['status'] = array(
                    'type' =>
                      array(
                        'succ' => '已发货',
                        'failed' => '发货失败',
                        'cancel' => '已取消',
                        'progress' => '等待配货',
                        'timeout' => '超时',
                        'ready' => '等待配货',
                        'stop' => '暂停',
                        'back' => '打回',
                    ),
                    'label' => '发货状态',
                    'comment' => '发货状态',
                    'editable' => false,
                    'filtertype' => 'yes',
                    'filterdefault' => true,
                    'in_list' => true,
                );
        }
        $sku = kernel::single('base_component_request')->get_get('sku');
        if (in_array($sku,array('single'))) {
            # 去除商品种类、商品总数量、发货单分组的panel_id
            unset($db['delivery']['columns']['skuNum']['panel_id'],
                $db['delivery']['columns']['delivery_group']['panel_id']);
        }
        return $db;
    }
}
